package com.leyou.trade.utils;

import com.leyou.auth.dto.UserDetails;
import com.leyou.auth.local.UserContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


@Component
public class CollectionNameCalculate {

    @Value("${ly.mongo. collectionNamePrefix}")
    public  String prefix;

    public  String calculate() {
        //1. 获取用户的id
        UserDetails user = UserContext.getUser();
        if(user == null){
            return "";
        }
        //2. 计算hash值,得到集合名
        int index = user.getId().hashCode() % 100;
        //3. 得到集合名称
        return prefix+index;
    }
}
